﻿using System;
using System.Linq;
using SimpleForum.Data.Services;

namespace SimpleForum.Classes.Achievements
{
    public class EditorAchievement : AchievementWorker
    {
        public EditorAchievement() : base() { }

        protected override void AwardAchievement()
        {
            var UserService = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<UserService>();
            var Users = UserService.GetUsers().ToList();

            foreach (var User in Users)
            {
                if (User.Posts.Where(x => x.LastEditDate != null).Count() >= 1) UserService.GiveAchievement(User.Id, UserService.AchievementType.EditorAchievement);
            }
        }

        protected override TimeSpan Interval
        {
            get
            {
                return new TimeSpan(1, 0, 00);
            }
        }
    }
}